<?php

use Phinx\Migration\AbstractMigration;

class CreateUserAuthenticationTable extends AbstractMigration
{
    public function up()
    {
        $table = $this->table('user_authentication', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '用户认证表']);

        //添加数据字段
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '用户认证ID'])
            ->addColumn('user_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '用户id'])
            ->addColumn('real_name', 'string', ['default' => '', 'null' => false, 'limit' => 255, 'comment' => '真实姓名'])
            ->addColumn('id_number', 'char', ['default' => '', 'null' => false, 'limit' => 18, 'comment' => '身份证号码'])
            ->addColumn('phone', 'char', ['default' => '', 'null' => false, 'limit' => 20, 'comment' => '手机号码'])
            ->addColumn('bank_account', 'char', ['default' => '', 'null' => false, 'limit' => 24, 'comment' => '银行账户'])
            ->addColumn('reasons_for_failure', 'text', ['null' => true, 'comment' => '未通过理由，通过清空'])
            ->addColumn('status', 'enum', ['values' => 'submitting,to_be_reviewed,active,invalid', 'default' => 'submitting', 'null' => false, 'comment' => '认证状态'])
            ->addColumn('updated', 'integer', ['signed' => false, 'default' => 0, 'null' => false, 'limit' => 11, 'comment' => '更新时间'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'default' => 0, 'null' => false, 'limit' => 11, 'comment' => '创建者'])
            ->addColumn('created', 'integer', ['signed' => false, 'default' => 0, 'null' => false, 'limit' => 11, 'comment' => '创建时间'])
            ->addColumn('json', 'json', ['null' => true, 'comment' => 'json字段，存储自定义字段'])
            ->addColumn('fdd_auth_status', 'integer', ['limit' => 2, 'default' => 0, 'null' => false, 'comment' => 'FDD认证状态'])
            ->addColumn('fdd_transaction_no', 'string', ['default' => "", 'limit' => 255, 'null' => false, 'comment' => 'FDD实名认证的序列号'])
            ->addColumn('fdd_auth_url', 'text', ['null' => true, 'comment' => 'FDD实名认证URL'])
            ->addColumn('fdd_auth_status_desc', 'string', ['limit' => 2048, 'null' => false, 'default' => '', 'comment' => 'FDD实名认证状态文字结果'])
            ->addColumn('fdd_cert_status', 'integer', ['limit' => 1, 'default' => 0, 'null' => false, 'comment' => 'FDD证书生成状态']);

        //执行创建
        $table->create();
    }

    public function down()
    {
        $this->table("user_authentication")->drop()->save();
    }
}
